﻿using System;
using System.Collections.Generic;
using System.Text;
using PostSharp.Aspects.Dependencies;

namespace Arcana.Contract.Argument.Is.Greater
{
    /// <summary>
    /// Provides a contract that adheres to <b>Argument Is Greater Than</b> semantic.
    /// </summary>
    [Serializable]
    [AspectRoleDependency(AspectDependencyAction.Commute, Roles.Conditional)]
    [ProvideAspectRole(Roles.Contract)]
    [ProvideAspectRole(Roles.Method)]
    [ProvideAspectRole(Roles.Argument)]
    [ProvideAspectRole(Roles.Conditional)]
    public sealed class ThanAttribute : ComparingContractBase
    {
        private object _value;
        
        /// <summary>
        /// Initializes a new instance of <b>Argument.Is.Greater.ThanAttribute</b>
        /// </summary>
        /// <remarks>
        /// Checks to see if the specified <i>argument</i> is always greater than <i>value</i>.
        /// </remarks>
        /// <param name="argumentName">The name of the argument to apply contract to.</param>
        /// <param name="value">The value to compare with argument.</param>
        public ThanAttribute(string argumentName, object value)
            : base(argumentName)
        {
            _value = value;
        }

        /// <summary>
        /// Performs validation on the argument.
        /// </summary>
        /// <param name="argument">The argument that should be validated.</param>
        /// <returns><b>true</b> if <i>argument</i> is validated, otherwise <b>false</b>.</returns>
        protected override bool ValidateArgument(object argument)
        {
            return Comparer.Compare(argument, _value) > 0;
        }
    }
}
